//
//  HMProposalDrug.swift
//  HealthMonitoring
//
//  Created by 珠海正杰 on 2018/9/3.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import LTScrollView
import MJRefresh


/// 档案管理 和 药物建议 都使用 这个Controller
class HMProposalDrug: HMViewController {

    open var variableControllers: [Any]?
    open var variableTitles: [String]?
    
    private lazy var layout: LTLayout = {  //全部样式这里搞？
        let layout = LTLayout()
        layout.isAverage = true
        layout.sliderWidth = 50
        layout.titleViewBgColor = UIColor.clear
        layout.titleSelectColor  = configure.shareConfigure.HMColor1
        layout.bottomLineColor = configure.shareConfigure.HMColor1
        return layout
    }()
    
    private lazy var pageView: LTPageView = {
        
        let statusBarH = UIApplication.shared.statusBarFrame.size.height
        let Y: CGFloat =  statusBarH + 44
        let H: CGFloat =  view.bounds.height - Y // glt_iphoneX ? (view.bounds.height - Y - 34) : view.bounds.height - Y
       
        var titles: [String]
        var viewControllers: [UIViewController]
        if (variableTitles?.count)! > 0 && (variableTitles?.count)! > 0 {
            titles = variableTitles!
            viewControllers = variableControllers! as! [UIViewController]
        }else {
            titles = ["---"]
            let oneVc  = HMProposalAll()
            oneVc._signStr = "---"
            viewControllers = [oneVc]
        }
  
        
        let pageView = LTPageView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: H), currentViewController: self, viewControllers: viewControllers, titles: titles, layout: layout)
        pageView.isClickScrollAnimation = true
//        pageView.backgroundColor = .clear
        return pageView
    }()
    
    
    /// MARK: -
    override func setupView() {
        view.backgroundColor = UIColor.white
        view.addSubview(pageView)
        //automaticallyAdjustsScrollViewInsets = false
        pageView.didSelectIndexBlock = {(_, index) in
            print("pageView.didSelectIndexBlock", index)
            if self.variableControllers != nil {
                print("\(self.variableTitles![index])")
                
                let ti = self.variableTitles![index]
                
                if  ti != "咨询设置" {
                    let all =  self.variableControllers![index] as! HMProposalAll
                    all.updateTable(type: all._signStr)  //table.reloadData()
                }
            
            }
        }
        
    }
    

    
    
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
    }
    
}

// LTSimpleScrollViewDelegate
//extension HMProposalDrug: LTSimpleScrollViewDelegate {
//    //MARK: 滚动代理方法
//    func glt_scrollViewDidScroll(_ scrollView: UIScrollView) {
//        //        print("offset -> ", scrollView.contentOffset.y)
//        scrollView.mj_header.endRefreshing()
//    }
//
//    //MARK: 控制器刷新事件代理方法
//    func glt_refreshScrollView(_ scrollView: UIScrollView, _ index: Int) {
//        //注意这里循环引用问题。
//        scrollView.mj_header = MJRefreshNormalHeader {[weak scrollView] in
//            DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
//                print("对应控制器的刷新自己玩吧，这里就不做处理了🙂-----\(index)")
//                scrollView?.mj_header.endRefreshing()
//            })
//        }
//    }
//}
//
extension HMProposalDrug {
    //MARK: 具体使用请参考以下
//    private func simpleManagerConfig() {
//
//        //MARK: headerView设置
//                simpleManager.configHeaderView {[weak self] in
//                    guard let strongSelf = self else { return nil }
//                    let headerView = strongSelf.testLabel()
//                    return headerView
//                }
//
//        //  simpleManager.registerCell(<#T##tableView: UITableView##UITableView#>, <#T##cellCls: AnyClass##AnyClass#>)
//
//        //MARK: pageView点击事件
//        simpleManager.didSelectIndexHandle { (index) in
//            print("选项点击了 \(index) 😆")
//        }
//
//    }

//    @objc private func tapLabel(_ gesture: UITapGestureRecognizer)  {
//        print("tapLabel☄")
//    }
}
